<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>首页</title>
    <link rel="stylesheet" th:href="@{/layui/css/layui.css}">
    <link rel="stylesheet" th:href="@{lib/css/main.css}">
    <link rel="stylesheet" th:href="@{/lib/css/public.css}">

    <script th:src="@{/lib/js/jquery-3.4.1.min.js}"></script>
    <script th:src="@{/layui/layui.js}"></script>


    <style>

        .layui-form input{
            width:215px;
        }
        .body{
            margin-left: 200px;
            height:800px;
        }
        #image2{
            wdith:100px;
            height: 100px;
        }
        .layui-upload-list{
            margin-left: 120px;

        }
        .layui-upload-img{
            wdith:100px;
            height: 100px;
        }
        body{
            background: url("images/background/page_bg.JPG");
            background-size: 100%;

        }
    </style>

    <script>
        layui.use('element', function(){
            var element = layui.element;

            //…
        });
        //上传照片
        layui.use('upload', function(){
            var $ = layui.jquery
                ,upload = layui.upload;

            //普通图片上传
            var uploadInst = upload.render({
                elem: '#test1'
                ,url: '/upload/'
                ,accept:'images'
                ,size:50000
                ,before: function(obj){

                    obj.preview(function(index, file, result){

                        $('#demo1').attr('src', result);
                    });
                }
                ,done: function(res){
                    //如果上传失败
                    if(res.code > 0){
                        return layer.msg('上传失败');
                    }
                    //上传成功
                    var demoText = $('#demoText');
                    demoText.html('<span style="color: #4cae4c;">上传成功</span>');

                    var fileupload = $(".stuImage");
                    fileupload.attr("value",res.data.src);
                    console.log(fileupload.attr("value"));
                }
                ,error: function(){
                    //演示失败状态，并实现重传
                    var demoText = $('#demoText');
                    demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                    demoText.find('.demo-reload').on('click', function(){
                        uploadInst.upload();
                    });
                }
            });


        });

    </script>
</head>
<body>
<!--<div th:replace="menu/left :: leftbar" ></div>-->
<!--<div th:replace="menu/top :: topbar"></div>-->
<div class="body">
    <h2 class="tablename">开通饲养师账号</h2>
    <hr class="layui-bg-gray">
    <div class="form">
        <br>
    <form id="form">
        账号：<input name="userName" id="username" type="text"/>
        密码：<input name="password" id="pwd" type="password"/>
        姓名：<input name="name" id="name" type="text" class="bi"/>
        性别：<input name="sex" id="sex" type="text" class="bi"/>

        擅长饲养：<input name="shanchang" id="siyang" type="text" class="bi"/>
        价格：<input name="price" id="price" type="text" class="bi"/>
        手机：<input name="phone" type="text" class="bi"/>
         <button onclick="kaitong()">开通</button>
    </form>
    </div>

</div>

<script>

    //添加宠物信息
    function kaitong(){

    var username = $("#username").val();

        var pwd = $("#pwd").val();
        var bi = $(".bi").val()

        if(username == null || username == ""){
            alert("请填写账号！")
            return false
        }

        if(pwd == null || pwd == ""){
            alert("请填写密码！")
            return false
        }

        if(bi == null || bi == ""){
            alert("请填写为空的字段！")
            return false
        }


        $.ajax({
            url:"/kaitong",
            type:"POST",
            data: $('#form').serialize(),
            success:function(data){
                if(data == 1){
                    alert("开通成功!");
                }
            },
            error:function(){
                alert("系统内部异常，请联系管理员！")
            }
        })


    }










    layui.use(['form', 'layedit', 'laydate'], function(){
        var form = layui.form
            ,layer = layui.layer
            ,layedit = layui.layedit
            ,laydate = layui.laydate;

        //日期
        laydate.render({
            elem: '#date1'
        });
        laydate.render({
            elem: '#date2'
        });


        //自定义验证规则
        form.verify({
            title: function(value){
                if(value.length < 5){
                    return '标题至少得5个字符啊';
                }
            }
            // ,password: [
            //     /^[\S]{6,12}$/
            //     ,'密码必须6到12位，且不能出现空格'
            // ]
            // ,username:[
            //     /^[\S]{2,}$/
            //     ,'用户名长度必须大于2，且不能出现空格'
            // ]
            ,content: function(value){
                layedit.sync(editIndex);
            }
        });


    });
</script>


</body>
</html>